
package com.gscitysfy.cus.drain.modules.assets.service.impl;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cloudfrmwk.data.mybatis.HerodotusIdentifierGenerator;
import com.gscitysfy.cloudfrmwk.portal.feign.UserService;
import com.gscitysfy.cloudfrmwk.portal.vo.UserInfoVO;
import com.gscitysfy.cloudfrmwk.security.definition.core.HerodotusUserDetails;
import com.gscitysfy.cloudfrmwk.security.utils.SecurityUtils;

import com.gscitysfy.cus.drain.modules.assets.entity.MoperAssetsEtRecord;
import com.gscitysfy.cus.drain.modules.assets.mapper.MoperAssetsEtRecordMapper;
import com.gscitysfy.cus.drain.modules.assets.service.IMoperAssetsEtRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author
 */
@Service
public class MoperAssetsEtRecordServiceimpl extends ServiceImpl<MoperAssetsEtRecordMapper, MoperAssetsEtRecord> implements IMoperAssetsEtRecordService {


    @Resource
    private UserService userService;


    /**
     * 查询操作类型
     *
     * @param page
     * @param coamId
     * @return
     */

    @Override
    public IPage<MoperAssetsEtRecord> list(Page<MoperAssetsEtRecord> page, String coamId) {
        LambdaQueryWrapper<MoperAssetsEtRecord> wrapper = new QueryWrapper<MoperAssetsEtRecord>().lambda().eq(StringUtils.isNotEmpty(coamId), MoperAssetsEtRecord::getCoamId, coamId);
        wrapper.orderByDesc(MoperAssetsEtRecord::getCoamAddtime);
        IPage<MoperAssetsEtRecord> iPage = baseMapper.selectPage(page, wrapper);
        return iPage;

    }


    /**
     * 保存操作类型数据
     *
     * @param contract
     * @return
     */

    @Override
    public Boolean saveContract(MoperAssetsEtRecord contract) {
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replace("-", "");
        contract.setCoamKid(uuid);
        HerodotusUserDetails principal = SecurityUtils.getPrincipal();
        if(principal!=null){
            contract.setCoamAccount(principal.getUsername());
            Result<UserInfoVO> userInfo = userService.getUserInfo();
            contract.setCoamCreator(userInfo.getData().getName());
        }
        contract.setCoamType(contract.getCoamType());
        contract.setCoamContent(contract.getCoamContent());
        contract.setCoamId(contract.getCoamId());
        contract.setCoamModifier(contract.getCoamModifier());
        contract.setCoamUsable(contract.getCoamUsable());
        Boolean save = this.save(contract);
        return save;
    }
}

